package com.megoc.menu.fragments;


import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.google.gson.Gson;
import com.megoc.menu.R;
import com.megoc.menu.adapter.MenuListAdapter;
import com.megoc.menu.model.collect.Menus;
import com.megoc.menu.utils.OkHttpClientManager;
import com.squareup.okhttp.Request;

/**
 * A simple {@link Fragment} subclass.
 */
public class CollectFragment extends Fragment {
    private final static String URL="http://api.haodou.com/index.php?appid=2&appkey=9ef269eec4f7a9d07c73952d06b5413f&format=json&sessionid=1444010831258&vc=76&vn=5.3.0&loguid=0&deviceid=haodou866938025500939&uuid=91dfbd0dffb6891be09b6f09952643db&channel=huawei_v530&method=Index.index&virtual=&signmethod=md5&v=2&timestamp=1444010957&nonce=0.8717754157596095&appsign=21cc975dc7da1b5e8fa31d6968088555";

    private ListView mListView;
    private Gson mGson;
    private MenuListAdapter mMenuListAdapter;
    public CollectFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_collect, container, false);
        mGson=new Gson();
        mListView= (ListView) view.findViewById(R.id.listview);
        OkHttpClientManager.getAsyn(URL, new OkHttpClientManager.ResultCallback<String>() {
            @Override
            public void onError(Request request, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Menus menu = mGson.fromJson(response, Menus.class);

                mMenuListAdapter = new MenuListAdapter(menu.getResult(), getContext());
                mListView.setAdapter(mMenuListAdapter);
            }
        });
        return view;
    }


}
